home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 March / macformat-022.iso / Shareware City / Graphics / SPD / Sources / sample.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-05-10  |  2.9 KB  |  104 lines  |  [TEXT/R*ch]

  1. /*
  2.  * sample.c - Simple file to make a scene with a few objects
  3.  *
  4.  * Author:  Alexander Enzmann
  5.  *
  6.  * Modified: 1 September 1993
  7.  *           Eric Haines
  8.  *           changed file name, made sure values were passed as doubles
  9.  *           (the HPUX compiler sees "..., 5, ..." as an integer and merrily
  10.  *           passes the integer representation down to the subroutine which
  11.  *           wants a double).
  12.  *
  13.  * size_factor is ignored.
  14.  *
  15.  *    size_factor    # spheres    # squares
  16.  *         x            xx             x
  17.  */
  18.  
  19. #include <stdio.h>
  20. #include <math.h>
  21. #include <stdlib.h>    /* atoi */
  22. #include "def.h"
  23. #include "drv.h"    /* display_close() */
  24. #include "lib.h"
  25.  
  26.  
  27. /* These may be read from the command line */
  28. static int size_factor      = 1;
  29. static int raytracer_format = OUTPUT_RT_DEFAULT;
  30. static int output_format    = OUTPUT_CURVES;
  31.  
  32. #ifdef OUTPUT_TO_FILE
  33. static FILE * stdout_file = NULL;
  34. #else
  35. #define stdout_file stdout
  36. #endif /* OUTPUT_TO_FILE */
  37.  
  38. static COORD3 Red     = { 1.0, 0.0, 0.0 };
  39. static COORD3 Cyan    = { 0.0, 1.0, 1.0 };
  40. static COORD3 Yellow  = { 1.0, 0.0, 1.0 };
  41. static COORD3 Magenta = { 1.0, 1.0, 0.0 };
  42.  
  43. int
  44. main(argc, argv)
  45.     int argc;
  46.     char *argv[];
  47. {
  48.     COORD3 back_color;
  49.     COORD4 from, at, up;
  50.     COORD4 center, normal;
  51.     COORD4 base, apex;
  52.  
  53.     PLATFORM_INIT(SPD_GENERIC);
  54.  
  55.     /* Start by defining which raytracer we will be using */
  56.      if ( lib_gen_get_opts( argc, argv,
  57.             &size_factor, &raytracer_format, &output_format ) ) {
  58.     return EXIT_FAIL;
  59.     }
  60.     if ( lib_open( raytracer_format, "Sample.out" ) ) {
  61.     return EXIT_FAIL;
  62.     }
  63.  
  64.     lib_set_polygonalization(8, 8);
  65.  
  66.     /* output background color - Light Grey */
  67.     /* NOTE: Do this BEFORE lib_output_viewpoint(), for display_init() */
  68.     SET_COORD3( back_color, 0.8, 0.8, 0.8 ) ;
  69.     lib_output_background_color( back_color ) ;
  70.  
  71.     SET_COORD3(from, 0, 5, -5);
  72.     SET_COORD3(at, 0, 0, 0);
  73.     SET_COORD3(up, 0, 1, 0);
  74.     lib_output_viewpoint(from, at, up, 45.0, 1.0, 0.001, 512, 512);
  75.  
  76.     SET_COORD4(center, -10, 20, -20, 1.0);
  77.     lib_output_light(center);
  78.  
  79.     lib_output_color(NULL, Cyan, 0.1, 0.7, 0.0, 0.7, 5.0, 0.0, 1.0);
  80.     SET_COORD3(center,-1, 0, 0);
  81.     SET_COORD3(normal, 1, 1,-0.5);
  82.     lib_output_torus(center, normal, 2.0, 0.5, output_format);
  83.  
  84.     lib_output_color(NULL, Magenta, 0.1, 0.7, 0.0, 0.7, 5.0, 0.0, 1.0);
  85.     SET_COORD3(center, 0, 0, 0);
  86.     SET_COORD3(normal, 0, 1,-0.5);
  87.     lib_output_torus(center, normal, 2.0, 0.5, output_format);
  88.  
  89.     lib_output_color(NULL, Yellow, 0.1, 0.7, 0.0, 0.7, 5.0, 0.0, 1.0);
  90.     SET_COORD3(center, 1, 0, 0);
  91.     SET_COORD3(normal,-1, 1,-0.5);
  92.     lib_output_torus(center, normal, 2.0, 0.5, output_format);
  93.  
  94.     lib_output_color(NULL, Red, 0.1, 0.7, 0.0, 0.7, 5.0, 0.0, 1.0);
  95.     SET_COORD4(base, 0, -2, 0, 2);
  96.     SET_COORD4(apex, 0,  2, 0, 0.1);
  97.     lib_output_cylcone(base, apex, output_format);
  98.  
  99.     lib_close();
  100.  
  101.     PLATFORM_SHUTDOWN();
  102.     return EXIT_SUCCESS;
  103. }
  104.